using System;
using System.Collections.Generic;

/// <summary>
/// Asset identifier manager.  tested in TestCenter
/// provides oneup seralization of assets
/// </summary>/

namespace Pixume.Core
{
	public class AssetIDManager
	{
		private HashSet<int> mRegisteredIDList;
		private int mIDPointer;

		public AssetIDManager()
		{
			mRegisteredIDList = new HashSet<int>();
			mIDPointer = 0;
		}
		public int GetNewID ()
		{
			while (mRegisteredIDList.Contains (mIDPointer)) {
				mIDPointer++;
				if(mIDPointer == System.Int32.MaxValue)
				{
					mIDPointer = 0;
				}
			}
			mRegisteredIDList.Add (mIDPointer);
			return mIDPointer;
		}

		public void RemoveID (int pID)
		{
			if(!IDExists (pID))
			{
				throw new KeyNotFoundException("Asset ID Manager: cannot remove ID, value [" + pID + "] not found!");
			}
			mRegisteredIDList.Remove (pID);
		}
		public bool IDExists(int pID)
		{
			return mRegisteredIDList.Contains (pID);
		}
	}
}

